<?php

/**
 * Evento form.
 *
 * @package    form
 * @subpackage Evento
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class EventoForm extends BaseEventoForm
{
  	public function configure()
  	{
  		parent::configure();
		unset($this['created_at'], $this['updated_at']);
		
		$this->widgetSchema['nm_evento'] = new sfWidgetFormInput(
			array(),
			array(
				'size' => 70,
				'maxlength' => 200
			)
		);
		
		$options = array('N'=>'Não', 'S'=>'Sim');
		$this->widgetSchema['st_evento'] = new sfWidgetFormChoice(
			array('choices'=>$options, 'expanded'=>true, 'multiple'=>false)
		);
		
		$this->widgetSchema['ds_resumo'] = new sfWidgetFormTextarea(
        	array(),
        	array('cols'=>70,'rows'=>5)
        );
		
		$this->widgetSchema['ds_evento'] = new sfWidgetFormTextarea(
			array(),
			array('id' => 'tinymce')
        );
        
        $this->widgetSchema['dt_evento'] = new sfWidgetFormInput(
			array(),
			array(
				'size' => 25,
				'maxlength' => 10,
				'class' => 'is_date_picker'
			)
		);
		
		$this->validatorSchema['dt_evento'] = new sfValidatori18nDate(array('required' => true));
		
		/*
       	 * Formulário embutido de mídia
       	 */
      	$form = new MidiaEventoForm(null, array(
			'item' => $this->getObject(),//nome do objeto
			'size'    => 10 //quantidade de registros
		));
        $this->embedForm('midia', $form);
		
  		$this->widgetSchema->setLabels(array(
  	      	'id_evento'  => '#ID',
	      	'nm_evento'  => 'Nome',
	      	'ds_evento'  => 'Descrição',
	      	'ds_resumo'  => 'Resumo',
	      	'st_evento'  => 'Publicado',
	      	'dt_evento'  => 'Data',
	      	'id_usuario' => 'Usuário',
	      	'created_at' => 'Criado em',
	      	'updated_at' => 'Atualizado em',
		));
  	}
  	
	public function saveEmbeddedForms($con = null, $forms = null)
	{
		if (null === $forms)
		{
			$midia = $this->getValue('midia');
			$forms = $this->embeddedForms;
			foreach ($this->embeddedForms['midia'] as $name => $form)
			{
				if (!isset($midia[$name]))
					unset($forms['midia'][$name]);
			}
		}
		parent::saveEmbeddedForms($con, $forms);
		 
		//Criando as Thumbs
		foreach($this->getObject()->getMidia() as $midia)
		{
			$thumb   = new Midia();
			$thumb->createThumb($midia);
		}

		return;
	}
}